package com.cn.wanxi.service;

import com.cn.wanxi.IO.FileModelIO;
import com.cn.wanxi.IOModel.NewsIOModel;
import com.cn.wanxi.model.NewsModel;
import com.cn.wanxi.util.IOUtil;

import java.util.Arrays;
import java.util.List;

public class NewsService {
    public List<NewsModel> getNewsList(){
        FileModelIO.writeData(IOUtil.NEWPATH.getPath(),new NewsIOModel().toString());
        String result = FileModelIO.readData(IOUtil.NEWPATH.getPath());
        String[] newData = FileModelIO.inputDataList(result,IOUtil.SPILT.getPath());
        System.out.println(Arrays.toString(newData));
        NewsModel newsModel = new NewsModel();
        String title = newData[0];
        String newsType = newData[1];
        String[] titles = title.split(",");
        String[] newsTypes = newsType.split(",");
        for (int i = 0; i < titles.length; i++) {
            NewsModel news = new NewsModel();
            news.setNewsType(newsTypes[i]);
            news.setTitle(titles[i]);
            news.setDate("2015-5-14");
            newsModel.list.add(news);
//            System.out.println(newsTypes[i] + ":" + titles[i]);
        }
        return newsModel.list;
    }

    public static void main(String[] args) {
        new NewsService().getNewsList();
    }
}
